﻿using Jesse_CookieBased.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Jesse_CookieBased.Controllers
{
    [Authorize]
    public class AdminController : Controller
    {
        public IActionResult Index()
        {
            
            String Name= HttpContext.User.Identity.Name;
            
            //授权类型
            String authenticationType = HttpContext.User.Identity.AuthenticationType;

            //是否认证通过
            bool isAuthenticated=HttpContext.User.Identity.IsAuthenticated;


            ViewBag.Name = Name;
            ViewBag.authenticationType = authenticationType;
            ViewBag.isAuthenticated = isAuthenticated;

            //ClaimsPrincipal就是用户的身份
            var claimsIdentity = HttpContext.User.Identity as ClaimsIdentity;

            CurrentUser user = new CurrentUser();
            user.Id = int.Parse(claimsIdentity.FindFirst("UserId")?.Value);
            user.Name = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
            user.UserName = claimsIdentity.FindFirst("UserName")?.Value;
            user.Role = claimsIdentity.FindFirst(ClaimTypes.Role)?.Value;
            user.MobilePhone = claimsIdentity.FindFirst(ClaimTypes.MobilePhone)?.Value;
            user.Email = claimsIdentity.FindFirst(ClaimTypes.Email)?.Value;
            user.Remark = claimsIdentity.FindFirst("Remark")?.Value;

            return View(user);
        }

        [AllowAnonymous]
        public IActionResult List()
        {
            return View();
        }
    }
}
